package com.byzk.invoice.xml.Doc_0.Annots;

import com.byzk.invoice.util.DocumentUtil;
import org.dom4j.*;

import java.io.File;

/**
 * 创建Annotations.xml.
 *
 * @author 康鹏 2020-05-21
 */
public class Annotations {

    /**
     * 创建Doc_0/Annots/Annotations.xml.
     * @param annotationsXmlPath Annotations.xml存放路径
     * @throws Exception Exception
     */
    public static void createAnnotationsXml(String annotationsXmlPath) throws Exception {

        Namespace namespace = new Namespace("ofd", "http://www.ofdspec.org/2016");
        //创建外层<ofd:Annotations />
        Element rootElt = DocumentHelper.createElement(new QName("Annotations", namespace));
        //创建<ofd:Page />
        Element pageElt = rootElt.addElement("ofd:Page");
        pageElt.addAttribute("PageID", "1");
        //创建<ofd:Page />
        Element fileLocElt = pageElt.addElement("ofd:FileLoc");
        fileLocElt.setText("Page_0/Annotation.xml");

        Document document = DocumentHelper.createDocument(rootElt);
        DocumentUtil.writer(document, annotationsXmlPath + File.separator + "Doc_0" + File.separator + "Annots"
                + File.separator + "Annotations.xml", true);
    }

}
